/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Bussiness;

import DatabaseAccess.DBHelper;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;

/**
 *
 * @author LeHieuIT
 */
public class NhapHang {
    private String Mahang;
    private String SoPhieu;
    private int SoLuongXuat;
    private String NgayXuat;
    private String MaKH;

    private DBHelper conn = new DBHelper();

   
    public String getMahang() {
        return Mahang;
    }

   
    public void setMahang(String Mahang) {
        this.Mahang = Mahang;
    }

    public String getSoPhieu() {
        return SoPhieu;
    }

    public void setSoPhieu(String SoPhieu) {
        this.SoPhieu = SoPhieu;
    }

    public int getSoLuongXuat() {
        return SoLuongXuat;
    }
  
    public void setSoLuongXuat(int SoLuongXuat) {
        this.SoLuongXuat = SoLuongXuat;
    }
    
    public String getNgayXuat() {
        return NgayXuat;
    }

   
    public void setNgayXuat(String NgayXuat) {
        this.NgayXuat = NgayXuat;
    }
    
    public String getMaKH() {
        return MaKH;
    }

   
    public void setMaKH(String MaKH) {
        this.MaKH = MaKH;
    }
    
    
    
     public NhapHang(){}
    public NhapHang(String Mahang, String SoPhieu, int SoLuongXuat, String NgayXuat,String MaKH){
        this.setMahang(Mahang);
        this.setSoPhieu(SoPhieu);
        this.setSoLuongXuat(SoLuongXuat);
        this.setNgayXuat(NgayXuat);
        this.setMaKH(MaKH);
      
    }
     public int insertNhapHang( NhapHang a) throws SQLException
    {
        int i = 0;
        try{
            Vector v = new Vector();
            v.add(a.getMahang());
            v.add(a.getSoPhieu());
            v.add(a.getSoLuongXuat());
            v.add(a.getNgayXuat());
            v.add(a.getMaKH());
            i=conn.executeUpdate("sp_InsertNhapHang",v);
        }catch(SQLException ex){}
        return i;
    }
      public int DelNhapHang(String MaHang) throws SQLException
    {
        int i=0;
        try
        {
            Vector paramList=new Vector();
            paramList.add(MaHang);           
            i=conn.executeUpdate("sp_DellNhapHang",paramList);
        }
        catch(SQLException sqlex)
        {
            
        }
        return i;
    }
    public Vector getAllNhapHang() throws SQLException
    {
        Vector v = new Vector();
        try 
        {
            ResultSet rs = conn.executeQuery("sp_getAllNhapHang");
            while(rs.next())
            {                  
                NhapHang b = new NhapHang();
                b.setMahang(rs.getString(1));
                b.setSoPhieu(rs.getString(2));
                b.setSoLuongXuat(rs.getInt(3));
                b.setNgayXuat(rs.getString(4));
                b.setMaKH(rs.getString(5));
                          
                v.add(b);                         
            }
        } 
        catch(SQLException sqle) 
        {            
        }
        return v;
    }
    public int updateNhapHang(NhapHang a) throws SQLException
    {
        DBHelper obj =new DBHelper();
        int i = 0;
        try{
            Vector v = new Vector();
            v.add(a.getMahang());
            v.add(a.getSoPhieu());
            v.add(a.getSoLuongXuat());
            v.add(a.getNgayXuat());
            v.add(a.getMaKH());
            i=obj.executeUpdate("sp_updateNhapHang",v);
        }catch(SQLException ex){}
        return i;
    }
    public Vector getNhapHang_MaHang(String Mahang) throws SQLException
    {
        Vector v = new Vector();
        Vector v1 = new Vector();
        v1.add(Mahang);
        try{
            ResultSet rs = conn.executeQuery("sp_getMaHang1", v1);
            while(rs.next()){
                NhapHang b = new NhapHang();
                b.setMahang(rs.getString(1));
                b.setSoPhieu(rs.getString(2));
                b.setSoLuongXuat(rs.getInt(3));
                b.setNgayXuat(rs.getString(4));
                b.setMaKH(rs.getString(5));
              
                v.add(b);
            }
        }catch(SQLException sqle) {}
        return v; 
    }
    
    public Vector getNhapHang_SoPhieu(String SoPhieu) throws SQLException
    {
        Vector v = new Vector();
        Vector v1 = new Vector();
        v1.add(SoPhieu);
        try{
            ResultSet rs = conn.executeQuery("sp_getSoPhieu", v1);
            while(rs.next()){
                NhapHang b = new NhapHang();
                b.setMahang(rs.getString(1));
                b.setSoPhieu(rs.getString(2));
                b.setSoLuongXuat(rs.getInt(3));
                b.setNgayXuat(rs.getString(4));
                b.setMaKH(rs.getString(5));
    
                v.add(b);
            }
        }catch(SQLException sqle) {}
        return v;
    }
    
 public Vector getNhapHang_NgayXuat(String NgayXuat) throws SQLException
    {
        Vector v = new Vector();
        Vector v1 = new Vector();
        v1.add(NgayXuat);
        try{
            ResultSet rs = conn.executeQuery("sp_getNgayXuat", v1);
            while(rs.next()){
                NhapHang b = new NhapHang();
                b.setMahang(rs.getString(1));
                b.setSoPhieu(rs.getString(2));
                b.setSoLuongXuat(rs.getInt(3));
                b.setNgayXuat(rs.getString(4));
                b.setMaKH(rs.getString(5));
              
                v.add(b);
            }
        }catch(SQLException sqle) {}
        return v;
    }
  public Vector getPhieuXNgay() throws SQLException
    {
        Vector v = new Vector();
        try 
        {
            ResultSet rs = conn.executeQuery("PhieuXuatTrongNgay");
            while(rs.next())
            {                  
                NhapHang b = new NhapHang();
                b.setMahang(rs.getString(1));
                b.setSoPhieu(rs.getString(2));
                b.setSoLuongXuat(rs.getInt(3));
                b.setNgayXuat(rs.getString(4)); 
                b.setMaKH(rs.getString(5));
                v.add(b);                         
            }
        } 
        catch(SQLException sqle) 
        {            
        }
        return v;
    }
}
    

